using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ACME.Northwind.Service.IOCExtensions
{
	internal static partial class ReflectionExtender
	{
		internal static bool ImplementsInterface(this Type objectType, Type interfaceType)
		{
			foreach (System.Type t in objectType.GetInterfaces())
			{
				if (t == interfaceType)
					return true;
				if (t.Name.Contains("`"))
				{
					if (t.Name == interfaceType.Name && t.Assembly == interfaceType.Assembly)
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static List<Type> GetCreatableObjectImplementsInterface(this Assembly assembly, Type interfaceType)
		{
			List<Type> retVal = new List<Type>();
			foreach (Type t in assembly.GetTypes())
			{
				if (t.ImplementsInterface(interfaceType) && !t.IsAbstract && !t.IsInterface)
					retVal.Add(t);
			}
			return retVal;
		}
	}
}
